home *** CD-ROM | disk | FTP | other *** search
- Path: uwm.edu!caen!usenet
- From: Jonathan Mayer <jmayer@umich.edu>
- Newsgroups: comp.lang.c++
- Subject: Optimizing Const Strings
- Date: Mon, 01 Apr 1996 23:46:34 -0500
- Organization: University of Michigan Engineering, Ann Arbor
- Message-ID: <3160B12A.41C67EA6@umich.edu>
- NNTP-Posting-Host: swallow.eecs.umich.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3_U1 sun4m)
-
- If I have an include file with a bunch of strings
- in it:
-
- typedef const char const * ConstStr;
- ConstStr strA = "aaa";
- ConstStr strB = "bbb";
- ConstStr strC = "ccc";
-
- And a program that uses only ONE of the aforementioned
- strings, all of the C-compilers I've tested (CSet++ and
- GCC) compile all three of the const strings into my
- program, even though only one of them was used.
-
- Is there any way I can define these strings so that the
- linker will refuse to link an unused string?
-
- (think: an include file listing lots of possible error
- messages, but a C++ program that only uses some of 'em).
-
- Back in the bad old C days, there was no problem having
- a bunch of #define'd strings, since only the utilized
- strings got instantiated in the program. However,
- since I'm trying to be typesafe ... shouldn't there
- by a typesafe way to replicate this functionality in C++?
- Is there a trick I've missed?
-
- Or it is a simple matter of: I'm declaring my data types
- correctly, but I'm expecting too much intelligence from
- the optimizer/linker?
-
- Sigh. Want my cake and eating it too.
-
- Please e-mail me replies ... USENET is too big and scary for me.
-
- Thanks,
- Jonathan. <jmayer@umich.edu>
- -------------------------- sig free -------------------------
-